package com.zq.recruit.controller;

import com.github.pagehelper.PageInfo;
import com.zq.common.util.Result;
import com.zq.recruit.dao.dto.JobPositionDto;
import com.zq.recruit.dao.entity.Company;
import com.zq.recruit.dao.entity.JobPosition;
import com.zq.recruit.service.CompanyService;
import com.zq.recruit.service.JobPositionService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 张乔
 * @Date 2025/3/16 16:41
 */
@RestController
@RequestMapping("/recruit/job")
public class JobPositionController {


@Resource
    private JobPositionService jobPositionService;

@Resource
private CompanyService companyService;



    //分页条件查询
    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    public Result<Object> findByPage(JobPositionDto sysUserDto ,
                                     @PathVariable(value = "pageNum") Integer pageNum ,
                                     @PathVariable(value = "pageSize") Integer pageSize) {
        PageInfo<JobPosition> pageInfo =jobPositionService.findByPage(sysUserDto,pageNum,pageSize);
        return     Result.successData(pageInfo);

    }

    @GetMapping("/getJobByName")
    public Result<Object> getJobByName(JobPositionDto sysUserDto) {
        List<JobPosition> pageInfo =jobPositionService.getJobByName(sysUserDto);
        return     Result.successData(pageInfo);

    }




    @GetMapping("/getAll")
    public Result<Object> getAll(){
   List<JobPosition> list= jobPositionService.listAll();
        return Result.successData(list);
    }

    @GetMapping("/getById/{id}")
    public Result<Object> findByPage(@PathVariable(value = "id") Integer id ) {

        JobPosition byId = jobPositionService.getById(id);
        Company byId1 = companyService.getById(byId.getCompanyId());
if(byId1!=null){
 byId.setCompanyName(byId1.getCompanyName());
byId.setCompanyPath(byId1.getImageUrl());
}
        return  Result.successData(byId);

    }






    @PostMapping("/addJob")
    public Result<String> addJob(@RequestBody JobPosition jobPosition){
        jobPositionService.save(jobPosition);
        return Result.success();
    }

    @PutMapping("/updateJob")
    public Result<String> updateJob(@RequestBody JobPosition jobPosition){
        jobPositionService.updateById(jobPosition);
        return Result.success();
    }

    @DeleteMapping("/deleteJob/{id}")
    public Result<String> deleteJob(@PathVariable("id") Integer id){
        jobPositionService.removeById(id);
        return Result.success();
    }








}
